
use "C:\Users\ejrnaes\OneDrive - Roskilde Universitet\Documents\Mads\G&O\ESS_FINAL_G&O.dta"

*Recoding leave variable as dummy variable
recode vteurmmb (1=0) (2=1) (44=0) (33=0) (55=0) (65=.a), generate (leave)

* keep
keep if leave==1 | leave==0

*Index Sorport for multiculturalism and trust in the political establishment
alpha trstprl trstlgl trstplc trstplt trstprt, gen ( trust)
alpha imueclt imwbcnt imbgeco , gen ( multi_culti )

*standardize of the independent variable
egen Zeducation1 =std(eduyrs)
egen Zincome1 =std( hinctnta )
egen Zmulti1 =std( multi_culti )
egen Ztrust1 =std( trust )

* sem figur 4
gsem (Ztrust1 -> leave, family(binomial) link(logit)) (Zmulti1 -> leave, family(binomial) link(logit)) (Zincome1 -> leave, family(binomial) link(logit)) (Zincome1 -> Ztrust1, ) (Zincome1 -> Zmulti1, ) (Zeducation1 -> leave, family(binomial) link(logit)) (Zeducation1 -> Ztrust1, ) (Zeducation1 -> Zmulti1, ) (M1[country_num] -> Ztrust1, ) (M2[country_num] -> leave, family(binomial) link(logit)) (M3[country_num] -> Zmulti1, ), covstruct(_lexogenous, diagonal) latent(M1 M2 M3 ) nocapslatent
melogit leave Zeducation1 Zincome1 Ztrust1 Zmulti1 || country_num:
margins, dydx(*) post



* Table 5. Decomposing Direct and Indirect Effects (KHB methods) for all country



 *standardize of the independent variable 
egen Zeducation2 =std(eduyrs)
egen Zincome2 =std( hinctnta )
egen Zmulti2 =std( multi_culti )
egen Ztrust2 =std( trust )
 
 
* group standardize
egen country_group = group(cntry)
sort country_group
by country_group : egen eduyrs_mean = mean( eduyrs )
by country_group : egen eduyrs_sd  = sd( eduyrs )
by country_group: gen  eduyrs_std = ( eduyrs-eduyrs_mean)/eduyrs_sd

sort country_group
by country_group : egen income_mean = mean(hinctnta)
by country_group : egen income_sd  = sd(hinctnta)
by country_group: gen  income_std = ( hinctnta-income_mean)/income_sd

sort country_group
by country_group : egen multi_culti_mean = mean(multi_culti)
by country_group : egen multi_culti_sd  = sd(multi_culti)
by country_group: gen  multi_culti_std = (multi_culti-multi_culti_mean)/multi_culti_sd

sort country_group
by country_group : egen trust_mean = mean(trust)
by country_group : egen trust_sd  = sd(trust)
by country_group: gen  trust_std = (trust-trust_mean)/trust_sd



*Table 5. Decomposing Direct and Indirect Effects (KHB methods) for all country 
* At 
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==1 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==1
margins, dydx(*) post

*BE
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==2 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==2
margins, dydx(*) post

*CZ
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==4 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==4
margins, dydx(*) post 

*FI
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==8 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==8
margins, dydx(*) post 

*FR
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==9 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==9
margins, dydx(*) post 

*DE
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==5 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==5
margins, dydx(*) post 


*HU
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==11 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==11
margins, dydx(*) post 



*IE
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==12 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==12
margins, dydx(*) post

*IT
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==15 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==15
margins, dydx(*) post 

*Lt
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==16 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==16
margins, dydx(*) post 


*NL
 khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==17 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==17
margins, dydx(*) post 
 
*PL
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==19 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==19
margins, dydx(*) post  
 
*PT
 khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==20 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==20
margins, dydx(*) post  
 
*SI
 khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==23 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==23
margins, dydx(*) post  

 *ES
khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==7 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==7
margins, dydx(*) post 
 
 *SE 
 
 khb logit leave  eduyrs_std income_std ||multi_culti_std trust_std  if country_num==22 ,   ape summary  
logit leave eduyrs_std income_std multi_culti_std trust_std  if country_num==22
margins, dydx(*) post 


*khb all (tjek)
khb logit leave Zeducation1 Zincome1 || Ztrust1 Zmulti1, concomitant (i.country_num)   ape summary
logit leave Zeducation1 Zincome1 Ztrust1 Zmulti1 i.country_num
margins, dydx(*) post
 
 
 *Appendix

recode mnactic (1=1 "paid work") (2/9=0), gen (Paidwork)
 
egen zage=std(age) 
 
egen Zemotion1=std(atchctr ) 
 
melogit leave zage i.gndr Zeducation1 Zincome1 Paidwork || country_num:
margins, dydx(*) post

melogit leave zage i.gndr Zeducation1 Zincome1 Paidwork Zmulti1 Ztrust1  Zemotion1 || country_num:
margins, dydx(*) post
 
 
 
 *SEM with age

 gsem (Zincome1 -> leave, family(binomial) link(logit)) (Zincome1 -> Ztrust1, ) (Zincome1 -> Zmulti1, ) (zage -> leave, family(binomial) link(logit)) (zage -> Ztrust1, ) (zage -> Zmulti1, ) (Zeducation1 -> leave, family(binomial) link(logit)) (Zeducation1 -> Ztrust1, ) (Zeducation1 -> Zmulti1, ) (Ztrust1 -> leave, family(binomial) link(logit)) (Zmulti1 -> leave, family(binomial) link(logit)) (M2[country_num] -> leave, family(binomial) link(logit)) (M1[country_num] -> Zmulti1, ) (M3[country_num] -> Ztrust1, ), covstruct(_lexogenous, diagonal) latent(M2 M1 M3 ) nocapslatent
 melogit leave Zeducation1 zage Zincome1 Ztrust1 Zmulti1 || country_num:
margins, dydx(*) post
 
* recode leave variable without dk
recode vteurmmb (1=0) (2=1) (33/65=.a), generate (leaveNy)
 
*GSem without dk
gsem (Ztrust1 -> leaveNy, family(binomial) link(logit)) (Zmulti1 -> leaveNy, family(binomial) link(logit)) (Zincome1 -> leaveNy, family(binomial) link(logit)) (Zincome1 -> Ztrust1, ) (Zincome1 -> Zmulti1, ) (Zeducation1 -> leaveNy, family(binomial) link(logit)) (Zeducation1 -> Ztrust1, ) (Zeducation1 -> Zmulti1, ) (M1[country_num] -> Ztrust1, ) (M2[country_num] -> leaveNy, family(binomial) link(logit)) (M3[country_num] -> Zmulti1, ), covstruct(_lexogenous, diagonal) latent(M1 M2 M3 ) nocapslatent
melogit leaveNy Zeducation1 Zincome1 Ztrust1 Zmulti1 || country_num:
margins, dydx(*) post
 

 
 
*UK 

use "C:\Users\ejrnaes\Dropbox\Public Attitudes\Our papers\Go your own way\G&O\UK_G&O_Final.dta" 

*Recoding leave variable as dummy variable
recode vteumbgb (1=0) (2=1) (44=0) (33=0) (55=0) (65=.a), generate (leave_UK)

* keep
keep if leave_UK==1 | leave_UK==0

*Index Sorport for multiculturalism and trust in the political establishment
alpha trstprl trstlgl trstplc trstplt trstprt, gen ( trust)
alpha imueclt imwbcnt imbgeco , gen ( multi_culti )

*UK
*standardize of the independent variable
egen Zeducation1 =std(eduyrs)
egen Zincome1 =std( hinctnta )
egen Zmulti1 =std( multi_culti )
egen Ztrust1 =std( trust )



*SEM figur 5
gsem (Ztrust1 -> leave_UK, family(binomial) link(logit)) (Zmulti1 -> leave_UK, family(binomial) link(logit)) (Zincome1 -> leave_UK, family(binomial) link(logit)) (Zincome1 -> Ztrust1, ) (Zincome1 -> Zmulti1, ) (Zeducation1 -> leave_UK, family(binomial) link(logit)) (Zeducation1 -> Ztrust1, ) (Zeducation1 -> Zmulti1, ), nocapslatent
 logit leave_UK  Zeducation1 Zincome1 Ztrust1 Zmulti1
margins, dydx(*) post
 
 
*UK KHb Table 5 
khb logit leave_UK Zeducation1 Zincome1||Zmulti1 Ztrust1 ,   ape summary  
logit leave_UK Zeducation1 Zincome1 Zmulti1 Ztrust1 
margins, dydx(*) post
 
 
 
 *UK_SEM med age
 
 egen zage=std(age) 

gsem (Ztrust1 -> leave_UK, family(binomial) link(logit)) (Zmulti1 -> leave_UK, family(binomial) link(logit)) (Zincome1 -> leave_UK, family(binomial) link(logit)) (Zincome1 -> Ztrust1, ) (Zincome1 -> Zmulti1, ) (zage -> leave_UK, family(binomial) link(logit)) (zage -> Ztrust1, ) (zage -> Zmulti1, ) (Zeducation1 -> leave_UK, family(binomial) link(logit)) (Zeducation1 -> Ztrust1, ) (Zeducation1 -> Zmulti1, ), nocapslatent
 logit leave_UK zage Zeducation1 Zincome1 Ztrust1 Zmulti1
margins, dydx(*) post
 

* Gsem without dk UK
 recode vteumbgb (1=0) (2=1) (33/65=.a), generate (leaveNyUK)
 
 logit leaveNyUK  Zeducation1 Zincome1 Ztrust1 Zmulti1
margins, dydx(*) post
 
 